#include<bits/stdc++.h>
using namespace std;
const int N=5e5+5;
long long t,n,m,a[N],w[N],top,lst,ans,fp;
struct node{
	int l,r;
}b[N];
struct node1{
	int mn,id;
}tree1[N*4+5],p,p1;
bool cmp(node i,node j)
{
	if(i.r==j.r) return i.l<j.l;
	return i.r<j.r;
}
node1 hb(node1 i,node1 j)
{
	node1 z;
	if(i.mn>=j.mn)
		z.mn=j.mn,z.id=j.id; 
	else
		z.mn=i.mn,z.id=i.id; 
	return z;
}
void build1(int l,int r,int id)
{
	if(l==r)
	{
		tree1[id].mn=a[l];
		tree1[id].id=l;
		return;
	}
	int mid=(l+r)/2;
	build1(l,mid,id*2);
	build1(mid+1,r,id*2+1);
	tree1[id]=hb(tree1[id*2],tree1[id*2+1]);
}
node1 cz1(int l,int r,int nl,int nr,int id)
{
	if(nl<=l&&r<=nr)
		return tree1[id];
	int mid=(l+r)/2;
	if(mid<nl) return cz1(mid+1,r,nl,nr,id*2+1);
	else if(mid>=nr) return cz1(l,mid,nl,nr,id*2);
	else return hb(cz1(l,mid,nl,nr,id*2),cz1(mid+1,r,nl,nr,id*2+1));
}
int main()
{
	freopen("gonna.in","r",stdin);
	freopen("gonna.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	cin>>m;
	build1(1,n,1);
	for(int i=1;i<=m;++i)
		cin>>b[i].l>>b[i].r;
	sort(b+1,b+m+1,cmp);
	top=1;
	for(int i=1;i<=n;++i)
	{
		while(b[top].r<=i&&top<=m)
		{
			if(lst==0)
			{
				p=cz1(1,n,b[top].l,b[top].r,1);
				lst=p.id;
				ans=p.mn;
				fp=b[top].r;
			}
			else if(b[top].l>lst){
				p=cz1(1,n,b[top].l,b[top].r,1);
				if(fp>=b[top].l)
				{
					p1=cz1(1,n,b[top].l,fp,1);
					if(p1.mn-a[lst]>=p.mn)
					{
						lst=p.id;
						ans+=p.mn;
						fp=b[top].r;
					}
					else
						ans+=p1.mn-a[lst],lst=p1.id;
				}
				else{
					lst=p.id;
					ans+=p.mn;
					fp=b[top].r;
				}
			}		
			++top;
		}
	 } 
	cout<<ans;
 	return 0;
 } 
